//
//  ShopHomeTableViewCell.m
//  GoShops
//
//  Created by zcj on 15-11-24.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//

#import "ShopHomeTableViewCell.h"
#import "Grouble.h"
#import "MerchantModel.h"

@interface ShopHomeTableViewCell()
@property (nonatomic,weak)UILabel* shopNameLabel;
@property (nonatomic,weak)UIImageView * xingxing;
@property (nonatomic,weak)UILabel* priceLabel;
// 多少人评价
@property (nonatomic,weak)UILabel* evaluation;
@end
@implementation ShopHomeTableViewCell
+(instancetype)ShopHomeTableViewCell:(UITableView *)tableView
{
    static NSString *menuID = @"shophomecell";
    ShopHomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:menuID];
    if (cell == nil) {
        cell = [[ShopHomeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:menuID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.userInteractionEnabled = YES;
        [self.imageView setImage:[UIImage imageNamed:@"bg_customReview_image_default"]];
        UIView * backView = [[UIView alloc]init];
        backView.frame = CGRectMake(0, 0, ScreenWidth, 120);
        backView.backgroundColor = [UIColor clearColor];
        [self addSubview:backView];
        
        CGFloat margn = 10;
        CGFloat shopImageW = 100;
        CGRect shopImg = CGRectMake(margn, margn, shopImageW, shopImageW);
        self.imageView.frame = shopImg;
        
        NSString * nameStr = @"小样";
        CGFloat nameX = CGRectGetMaxX(shopImg) + 2*margn;
        CGSize nameH = [nameStr sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]}];
        CGFloat nameW = ScreenWidth - 80 - margn * 5;
        
        CGRect shopNameLabelRect = CGRectMake(nameX, margn, nameW, nameH.height);
        UILabel* shopNameLabel = [[UILabel alloc]initWithFrame:shopNameLabelRect];
        shopNameLabel.font = [UIFont systemFontOfSize:16];
        
        [backView addSubview:shopNameLabel];
        self.shopNameLabel = shopNameLabel;
        // 星星
        CGFloat sunX = nameX;
        CGFloat sunY = margn*2 + nameH.height;
        CGFloat sunW = nameW;
        CGFloat sunH = nameH.height;
        CGRect sunRect = CGRectMake(sunX, sunY, sunW, sunH);
        //
        UIImageView * xingxing = [[UIImageView alloc]init];
        xingxing.backgroundColor = [UIColor redColor];
        xingxing.contentMode = UIViewContentModeLeft;
        [xingxing setImage:[UIImage imageNamed:@"icon_feedCell_star_empty"]];
        xingxing.frame = CGRectZero;
        xingxing.frame = CGRectMake(sunX, sunY, xingxing.image.size.width, xingxing.image.size.height);
        
        [backView addSubview:xingxing];

        // 多少人评价
        CGFloat evaluationX = nameX + 6 *margn;
        CGFloat evaluationY = sunY;
        CGFloat evaluationW = 90;
        CGFloat evaluationH = nameH.height;
        CGRect evaluationSize = CGRectMake(evaluationX, evaluationY, evaluationW, evaluationH);
        
        UILabel * evaluation = [[UILabel alloc]initWithFrame:evaluationSize];
        evaluation.textColor = [UIColor blackColor];
        
      
        evaluation.font = [UIFont systemFontOfSize:10];
        evaluation.textAlignment = NSTextAlignmentRight;
        
        [backView addSubview:evaluation];
        self.evaluation = evaluation;
        // 例子：美发  中关村
        CGFloat priceX = sunX;
        CGFloat priceY = CGRectGetMaxY(sunRect) + margn;
        CGFloat priceW = sunW;
        CGFloat priceH = sunH;
        CGRect priceRect = CGRectMake(priceX, priceY, priceW, priceH);
        
        UILabel * priceLabel = [[UILabel alloc]initWithFrame:priceRect];
        priceLabel.numberOfLines = 0;
        priceLabel.textColor = [UIColor blackColor];
        priceLabel.font = [UIFont systemFontOfSize:12];
        priceLabel.textAlignment = NSTextAlignmentLeft;
        
        [backView addSubview:priceLabel];
        self.priceLabel = priceLabel;
        

        // Initialization code
    }
    return self;
}
// 设置数据
- (void)setMerchant:(MerchantModel *)merchant
{
    _merchant = merchant;
     NSString *imgUrl = [merchant.frontImg stringByReplacingOccurrencesOfString:@"w.h" withString:@"160.0"];
    [self.imageView setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"meishizhan"]];
    // 名称
    self.shopNameLabel.text = merchant.name;

    // 地点加类型
    self.priceLabel.text = [NSString stringWithFormat:@"%@  %@",merchant.cateName,merchant.areaName];
    // 评价
    self.evaluation.text = [NSString stringWithFormat:@"%@评价",merchant.markNumbers];

    
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat margn = 10;
    CGFloat shopImageW = 100;
    CGRect shopImg = CGRectMake(margn, margn, shopImageW, shopImageW);
    
    self.imageView.frame = shopImg;
}
- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
